package com.fdm.model.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.fdm.model.Customer;

public class OracleCustomerDAO implements CustomerDAO {

	public Customer getCustomer(long id) throws SQLException {
		String sqlStatement="SELECT cust_id, firstname, lastname, email, dob FROM CUSTOMERS WHERE id=?";
		Connection conn = OracleDAOFactory.createConnection();
		PreparedStatement ps= conn.prepareStatement(sqlStatement.toLowerCase());
		ps.setLong(1, id);
		ResultSet rs=ps.executeQuery(sqlStatement);
		Customer customer=new Customer();
		while(rs.next()){
			customer.setId(rs.getLong(1));
			customer.setFirstname(rs.getString(2));
			customer.setLastname(rs.getString(3));
			customer.setEmail(rs.getString(4));
			customer.setDob(rs.getDate(5));
		}
		return customer;
	}

	public Customer getCustomer(String email) throws SQLException {
		String sqlStatement="SELECT cust_id, firstname, lastname, email, dob FROM CUSTOMERS WHERE email=?";
		Connection conn = OracleDAOFactory.createConnection();
		PreparedStatement ps= conn.prepareStatement(sqlStatement);
		ps.setString(1, email);
		ResultSet rs=ps.executeQuery(sqlStatement);
		Customer customer=new Customer();
		while(rs.next()){
			customer.setId(rs.getLong(1));
			customer.setFirstname(rs.getString(2));
			customer.setLastname(rs.getString(3));
			customer.setEmail(rs.getString(4));
			customer.setDob(rs.getDate(5));
		}
		return customer;
	}
	
	public void createNewCustomer(Customer customer) {
		// TODO Auto-generated method stub

	}

	public void updateCustomer(Customer customer) {
		// TODO Auto-generated method stub

	}

	public void deleteCustomer(long id) {
		// TODO Auto-generated method stub

	}

}
